1 // Fig 12.2: fig12_02.cpp 2 // Using template functions 3 #include 4 5 template< class T > 6 void printArray( const T *array, const int count ) 7 { 8 for ( int i = 0; i < count; i++ ) 9 cout << array[ i ] << " "; 10 11 cout << endl; 12 } 13 14 int main() 15 { 16 const int aCount = 5, bCount = 7, cCount = 6; 17 int a[ aCount ] = { 1, 2, 3, 4, 5 }; 18 double b[ bCount ] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 }; 19 char c[ cCount ] = "HELLO"; // 6th position for null 20 21 cout << "Array a contains:" << endl; 22 printArray( a, aCount ); // integer template function 23 24 cout << "Array b contains:" << endl; 25 printArray( b, bCount ); // double template function 26 27 cout << "Array c contains:" << endl; 28 printArray( c, cCount ); // character template function 29 30 return 0; 31 }